<template>
  <div class="CommodityList">
    <div class="lubo">
      <Slideshow :luobo="vanswipe"></Slideshow>
    </div>

    <div style="height: 1px"></div>
    <Recommend :tobufenl="ToRecommend"></Recommend>
    <!-- <div style="height: 5px"></div> -->
    <Discount></Discount>
    <!-- 推荐列表 -->
    <div class="tjian">
      <Lazyloading :waterData="waterInfo"></Lazyloading>
    </div>
  </div>
</template>

<script>
import API from "../http/API";
import { Search } from "vant";
import Slideshow from "@/components/Slideshow.vue";
import Recommend from "./Recommend/ToRecommend.vue";
import Discount from "./Recommend/Discount.vue";
import Lazyloading from "./Lazyloading.vue";
export default {
  name: "search",

  components: {
    Recommend,
    Slideshow,
    Discount,
    Lazyloading,
    [Search.name]: Search,
  },
  data() {
    return {
      // indexdata: [],
      value: "",
      hint: ["搜索", "取消"],

      finished: false,
      waterInfo: [],

      // 全部数据

      complete: [],
      // 大类数据
      ToRecommend: [],
      // 轮播图数据
      vanswipe: [],
    };
  },
  created() {
    this.nadaoshuju();
  },
  activated() {
    // 通过页面下标来拿
    this.http();
  },
  provide() {
    return {};
  },
  mounted() {},
  methods: {
    nadaoshuju() {
      let indexdata = [];
      this.$get(API.GET_HOME_INFO, {}).then((res) => {
        indexdata = res.data;
        this.complete.push(indexdata.newGoodsList);
        this.complete.push(indexdata.hotGoodsList);
        this.complete.push(indexdata.grouponList);
        this.ToRecommend.push(indexdata.channel);
        this.vanswipe = indexdata.banner;
        this.ToRecommend[0].splice(8, 9);
        this.ToRecommend.push([
          {
            lei: 4,
          },
        ]);
        this.ToRecommend.push([
          {
            border: true,
          },
        ]);
        // console.log(this.ToRecommend);
        this.gather(this.complete);
      });

      // console.log(this.$store.state.indexdata);
      this.http();
    },

    // 进行数据的聚合
    gather(e) {
      for (let index = 0; index < e.length; index++) {
        for (let i = 0; i < e[index].length; i++) {
          this.waterInfo.push(e[index][index]);
        }
      }
    },
    // 拿到购物车的数据
    http() {
      this.$get(API.GET_CART_INDEX, {
        token: this.$store.state.token,
      }).then((res) => {
        if (res.errmsg == "成功") {
        
            this.$store.commit("shoppingAmount", res.data.cartList.length);
            // console.log("走了生命周期"+this.$store.state.shoppingamount);
          
        
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.tjian {
  .sj();
  padding-bottom: 50px;
}
.CommodityList {
  background-color: @background;
  position: relative;
  .lubo {
    height: 150px;
  }
}
</style>